# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=flac
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.3
pkgrel=1
pkgdesc="Free Lossless Audio Codec (mingw-w64)"
arch=('any')
url="https://flac.sourceforge.io/"
license=('custom:Xiph' 'LGPL' 'GPL' 'FDL')
depends=("${MINGW_PACKAGE_PREFIX}-libogg" "${MINGW_PACKAGE_PREFIX}-gcc-libs")
#optdepends=("${MINGW_PACKAGE_PREFIX}-xmms: for using the xmms plugin")
makedepends=("${MINGW_PACKAGE_PREFIX}-nasm" "${MINGW_PACKAGE_PREFIX}-gcc")
options=('strip' 'staticlibs')
source=("https://downloads.xiph.org/releases/flac/flac-${pkgver}.tar.xz")
sha256sums=('213e82bd716c9de6db2f98bcadbc4c24c7e2efe8c75939a1a84e28539c4e1748')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  #Required as AM_CONFIG_HEADER is deprecated and causes autotools to error out.
  #sed -i "s/\<AM_CONFIG_HEADER\>/AC_CONFIG_HEADERS/g" configure.in

  touch config.rpath
  #./autogen.sh
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --enable-shared \
    --enable-static \
    --disable-xmms-plugin \
    --disable-rpath \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-pic
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
